package cn.kgc.crowdfundingadmin02.controller;

import cn.kgc.crowdfundingadmin02.common.ResultEntity;
import cn.kgc.crowdfundingadmin02.pojo.Auth;
import cn.kgc.crowdfundingadmin02.service.AuthService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author shkstart
 * @create 2020-03-03 21:05
 */
@Controller
public class AuthController {

    @Resource
    AuthService authService;
    @ResponseBody
    @RequestMapping("/assign/get/all/auth")
    public ResultEntity<List<Auth>> getAllAuth() {
        List<Auth> allAuth = authService.getAllAuth();
return ResultEntity.successWithoutData(allAuth);
    }

    @ResponseBody
    @RequestMapping("/assign/get/assigned/auth/id/list")
    public ResultEntity<List<Integer>> getAssignedAuthIdList(@RequestParam("roleId") Integer roleId) {
        List<Integer> assignedAuthIdList = authService.getAssignedAuthIdList(roleId);
        return  ResultEntity.successWithoutData(assignedAuthIdList);
    }

/*
    @ResponseBody
    @RequestMapping("/assign/do/assign")
    public ResultEntity<String> doRoleAssignAuth(
            @RequestBody Map<String, List<Integer>> assignDataMap) {
        authService.updateRelationShipBetweenRoleAndAuth(assignDataMap);
        return  ResultEntity.successWithoutData();

    }
*/

    @ResponseBody
    @RequestMapping("/assign/do/assign")
    public ResultEntity<String> doRoleAssignAuth(
            @RequestBody Map<String, List<Integer>> assignDataMap) {

        authService.updateRelationShipBetweenRoleAndAuth(assignDataMap);

        return ResultEntity.successWithoutData();
    }

}
